#include "Socket.hpp"
#include "Epoll.hpp"
#include <string>
#include <functional>

class Connection
{
public:
    Connection(int sockFd, \
            const std::function<void(const std::string&)>& onConnected, \
            const std::function<void(const std::string&)>& onDisconnected, \
            const std::function<void(const std::string&)>& onMessage, \
            Epoll* epoller,
            _events = 0)
        :_sockFd(sockFd), \
        _onConnected(onConnected), _onDisconnected(onDisconnected), _onMessage(onMessage), \
        _epoller(epoller), _events(0)
    {}

    void SetOnMessage(const std::function<void(const std::string&)>& onMessage)
    {
        _onMessage = onMessage;
    }

    int Fd() const
    {
        return _sockFd;
    }

    int Events() const
    {
        return _events;
    }

    std::function<void(const std::string&)>& onMessage()
    {
        return _onMessage;
    }

private:
    int _sockFd;
    Epoll* _epoller;
    std::function<void(const std::string&)> _onConnected;
    std::function<void(const std::string&)> _onDisconnected;
    std::function<void(const std::string&)> _onMessage;
    std::string _inBuffer;
    std::string _outBuffer;
    int _events;
};